<template>
    <div>
        <el-dialog :visible.sync="dialog" :title="title" :width="inline ? '800px':'600px'" @close="closeDialog">
            <el-form label-position="right" :inline="inline" ref="formRef" :rules="rules" label-width="150px" :model="model">
                <el-form-item v-for="item in column" :label="item.label" :prop="item.prop">
                    <!--使用change{label: '期间', prop: 'periodFlag', type: 'select', option: [], change: (model) => {model.parameterName = 1111}}-->
                    <el-select v-if="item.type == 'select'" size="small" v-model="model[item.prop]" filterable :clearable="item.clearable == null ? true:item.clearable" :disabled="item.disabled" :placeholder="item.label" @change="item.change != null ? item.change(model) :''">
                        <el-option v-for="item in item.option" :key="item.dicCode" :label="item.dicName" :value="item.dicCode"></el-option>
                    </el-select>
                    <el-input-number v-else-if="item.type == 'input-number'" size="small" class="ein" v-model="model[item.prop]" :disabled="item.disabled" :precision="item.precision" :step="item.step" :max="item.max"  @change="item.change != null ? item.change(model) :''"></el-input-number>
                    <el-input v-else size="small" :placeholder="item.label" :clearable="item.clearable == null ? true:item.clearable" :disabled="item.disabled" v-model="model[item.prop]"  @change="item.change != null ? item.change(model) :''"/>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
			    <el-button @click="closeDialog">取 消</el-button>
			    <el-button type="primary" :loading="btnLoading" @click="saveValidate">保 存</el-button>
			  </span>
        </el-dialog>
    </div>
</template>
<script>
  import { clearValidate } from '@/utils/util';

  export default {
    props: ['title', 'rules', 'model', 'column', 'inline'],
    data() {
      return {
        dialog: false, //对话框
        btnLoading: false
      };
    },
    mounted() {
      //console.log('exportVisibleDefault', this.exportVisibleDefault);
    },
    methods: {
      closeDialog() {
        this.dialog = false;
      },
      saveValidate() {
        this.btnLoading = true;
        this.$refs['formRef'].validate(async (valid) => {
          if (valid) {
            this.$emit('save', this.model);
          } else {
            this.btnLoading = false;
            return false;
          }
        });
      },
      initStatus(dialog) {
        this.dialog = dialog;
        this.clearStatus();
      },
      clearStatus() {
        this.btnLoading = false;
        clearValidate(this, 'form', ''); //清空表单验证和数据
      },
      setBtnLoading(status){
        this.btnLoading = status;
      }
    }
  };
</script>
<style scoped>
</style>
